package com.dou.config;

import com.dou.utils.Tools;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA 2021.1 x64
 *
 * @Author: 窦义超
 * @Date: 2021/07/2021/7/19/13:44
 * @Description:
 */
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //登陆成功之后，应该有session
        String loginUser = (String) request.getSession().getAttribute("loginUser");
        if(Tools.count==0){
            request.getRequestDispatcher("/index.html").forward(request,response);
            Tools.count++;
            return false;
        }else if (loginUser==null){
            request.setAttribute("msg","没有权限请先登录");
            request.getRequestDispatcher("/index.html").forward(request,response);
        return false;
        }else {
            return true;
        }
    }
}
